home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13202 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: solon.com!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated,hp.unix,comp.sys.hp.apps,comp.sys.hp.hpux
  4. Subject: Re: C coding problem
  5. Date: 4 Apr 1996 18:50:24 -0600
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4k1qog$5mg@solutions.solon.com>
  10. References: <4ianbf$h86@solutions.solon.com> <4j41ru$nq4@solutions.solon.com> <4jttlq$3p1@solutions.solon.com> <4jv7dk$d1k@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12.  
  13. In article <4jv7dk$d1k@solutions.solon.com>,
  14. Konrad Schwarz <schwarz@mips.complang.tuwien.ac.at> wrote:
  15.  
  16. >|> >for ( ; p<end_p; p++) 
  17. >|> >    ++(*p);
  18. >|> 
  19. >|> or either of:
  20. >|> 
  21. >|> while (p < end_p)
  22. >|> {
  23. >|>     (*p)++;
  24. >|>     p++;
  25. >|> }
  26. >|> 
  27. >|> while (p++ < end_p)
  28. >|> {
  29. >|>     (*p)++;
  30. >|> }
  31. >|> 
  32. >|> Zero chance for ambiguity in the last three versions.
  33. >
  34. >The third version is not equivalent to the other two.
  35.  
  36. By golly, you are right!
  37.  
  38. It looks that our critic of obfuscated coding thinks that the side effect of
  39. p++ in the while() statement is not settled until the whole body of while()
  40. (including the compound statement) is executed---a common newbie assumption. I
  41. can see why  he would want people to write code like:
  42.  
  43. while (p < end_p)
  44. {
  45.     *p = *p + 1;
  46.     p = p + 1;
  47. }
  48.  
  49. instead of
  50.  
  51. while (p < end_p)
  52.     ++*p++;
  53.  
  54. -- 
  55.